package TCPTest02;

import java.io.*;
import java.net.Socket;

public class Client {
    /**
     * 客户端：发送一条数据给服务端，并接收服务端发送的数据并打印
     * @param args
     */
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",10000);
        //写出数据
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("见到你很高兴".getBytes());
        //写出一个结束标记
        socket.shutdownOutput();
        //接收服务端回写的数据
        InputStream inputStream = socket.getInputStream();
        InputStreamReader reader = new InputStreamReader(inputStream);
        BufferedReader br = new BufferedReader(reader);
        int b;
        while ((b=br.read())!= -1){
            System.out.print((char) b);
        }
        socket.close();

    }
}
